using System;
using NHibernate;
using NHibernate.Classic;
using NUnit.Framework;
using TestClass = NUnit.Framework.TestFixtureAttribute;
using TestMethod = NUnit.Framework.TestAttribute;
using TestInitialize = NUnit.Framework.SetUpAttribute;
using TestCleanup = NUnit.Framework.TearDownAttribute;
using ClassInitialize = NUnit.Framework.TestFixtureSetUpAttribute;
using ClassCleanup = NUnit.Framework.TestFixtureTearDownAttribute;
using Blazing.BusinessObjects.Locations;


namespace BusinessObjectTests
{
    [TestClass]
    public class LocationTests : NHibernateInMemoryTestFixtureBase
    {
        [TestMethod]
        public void CanLoadChildLocations()
        {
            Location loc = BusinessObjectFactory.CreateAndFillLocation();
            loc.Save();

            int id = loc.ID;

            ITransaction trans = session.BeginTransaction();
            
            Location loc2 = Location.Load(id);
            Assert.AreEqual(0, loc2.ChildLocations.Count);
            trans.Commit();
        }

        [TestMethod]
        [ExpectedException(typeof(ValidationFailure))]
        public void CanNotBeOwnParent()
        {
            Location loc = BusinessObjectFactory.CreateAndFillLocation();

            loc.ParentLocation = loc;

            loc.Save();
        }
    }
}
